import { takeEvery, put } from "redux-saga/effects";
import { loadProducts, saveProducts } from "../actions/product.actions";
import axios from 'axios';

function* handleLoadProducts() {
  // 加载商品数据
  const { data } = yield axios.get('http://localhost:3005/goods');
  // 把数据保存到store中
  yield put(saveProducts(data));
}

export default function* productSaga(){
  yield takeEvery(loadProducts, handleLoadProducts);
}